home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Grafik / Misc / ImageEnginer / ARexx / Batch / Crop.ieb < prev    next >
Encoding:
Text File  |  1997-02-02  |  4.3 KB  |  155 lines

  1. /*
  2. ** $VER: Crop.ieb 1.21, IE Arexx script
  3. ** Image Engineer Batch Processing script
  4. ** Copyright © by Patrik M Nydensten
  5. ** 2/2 1997 Stockholm/Sweden
  6. **
  7. ** Crop image with Xoff, Yoff, Width and Height.
  8. */
  9.  
  10. options results
  11. signal on error
  12.  
  13. parse arg input command
  14. input = upper(strip(input))
  15. address 'IMAGEENGINEER'
  16.  
  17. select  /* Required batch script commands */
  18.   when input = 'INFO' then    return get_info()
  19.   when input = 'CONFIG' then  return get_config(command)
  20.   when input = 'PROCESS' then return process_image(command)
  21.   otherwise do
  22.     'REQUEST' '"Failure in call to batch script!"' '" Quit "'
  23.     return '<ERROR>'
  24.   end
  25. end
  26.  
  27. exit 0
  28.  
  29. /* Required "Get_info" procedure  ------------------------------------ */
  30. /* S = SECONDARY, A = ALPHA, 1 = Single file, 2 = Multiple files       */
  31.  
  32. get_info:
  33.   back = 'OK'
  34. return back
  35.  
  36. /* Required "Get_config" procedure  ---------------------------------- */
  37.  
  38. get_config:
  39.   parse arg '"'command'"'
  40.  
  41.   Xoff=0 ; Yoff=0 ; type = 9 ; Width=128 ; Height=128 ; XXoff=100 ; YYoff=100 ; BXoff=-10 ; BYoff=-10
  42.  
  43.   if command ~= '' then parse var command Xoff Yoff '#'type Width Height XXoff YYoff BXoff BYoff .
  44.  
  45.   'IE_TO_FRONT'
  46.  
  47.   form = 'FORM "Crop" " OK | Cancel "',
  48.   ' INTEGER,"X offset",0,4096,'Xoff',SLIDER',
  49.   ' INTEGER,"Y offset",0,4096,'Yoff',SLIDER'
  50.  
  51.   if command = '' then form = form||' CYCLE,"Type:","Use Width & Height|Use X2 & Y2 offset|Use X & Y back offset",0'
  52.  
  53.   if (type=0)|(type=9) then form = form||' INTEGER,"Width",2,4096,'Width',SLIDER',
  54.   ' INTEGER,"Height",2,4096,'Height',SLIDER'
  55.  
  56.   if (type=1)|(type=9) then form = form||' INTEGER,"X2 offset",0,4096,'XXoff',SLIDER',
  57.   ' INTEGER,"Y2 offset",0,4096,'YYoff',SLIDER'
  58.  
  59.   if (type=2)|(type=9) then form = form||' INTEGER,"X back offset",-4096,0,'BXoff',SLIDER',
  60.   ' INTEGER,"Y back offset",-4096,0,'BYoff',SLIDER'
  61.  
  62.   if command = '' then do
  63.     form
  64.     parse var result ok Xoff Yoff type Width Height XXoff YYoff BXoff BYoff .
  65.     if ok = 0 then return '<ERROR>'
  66.   end
  67.   else do
  68.     form
  69.     parse var result ok Xoff Yoff a b .
  70.     if ok = 0 then return '<ERROR>'
  71.  
  72.     if type = 0 then do; Width = a; Height = b; end
  73.     if type = 1 then do; XXoff = a; YYoff = b; end
  74.     if type = 2 then do; BXoff = a; BYoff = b; end
  75.  
  76.     type = 'none'
  77.   end
  78.  
  79.   back = Xoff Yoff '#'type Width Height XXoff YYoff BXoff BYoff
  80. return back
  81.  
  82. /* Required "Process_image" procedure  ------------------------------- */
  83.  
  84. process_image:
  85.   parse arg '"'src_image'"' '"'dst_image'"' '"'options'"'
  86.   parse var options Xoff Yoff '#'type Width Height XXoff YYoff BXoff BYoff .
  87.  
  88.   'OPEN' '"'src_image'"' '24'
  89.   if (RC ~= 0) then do
  90.     'IE_TO_FRONT'
  91.     'REQUEST' '"Failed to load image:' d2c(10)||src_image'"' '" OK "'
  92.     return '<ERROR>'
  93.   end
  94.   else LoadImage = result
  95.  
  96.   'PROJECT_INFO' LoadImage 'WIDTH'    /* Get width of image */
  97.   IW = RESULT
  98.   'PROJECT_INFO' LoadImage 'HEIGHT'    /* Get height of image */
  99.   IH = RESULT
  100.  
  101.   if type = 0 then do
  102.     XXoff = Xoff + Width -1
  103.     YYoff = Yoff + Height -1
  104.   end
  105.   if type = 2 then do
  106.     XXoff = IW + BXoff
  107.     YYoff = IH + BYoff
  108.   end
  109.  
  110.   if Xoff > IW then Xoff = IW
  111.   if Yoff > IH then Yoff = IH
  112.  
  113.   if XXoff > IW then XXoff = IW
  114.   if YYoff > IH then YYoff = IH
  115.  
  116.   if XXoff < 0 then XXoff = 0
  117.   if YYoff < 0 then YYoff = 0
  118.  
  119.   'CROP' LoadImage min(Xoff,XXoff) min(Yoff,YYoff) max(Xoff,XXoff) max(Yoff,YYoff)
  120.   OutputImage = Result
  121.   'CLOSE' LoadImage
  122.  
  123.   if getclip('cfg_save_frmt')='' then setclip('cfg_save_frmt','ILBM CmpByteRun1')
  124.   'SAVE_DATA' OutputImage '"'dst_image'"' '"'getclip('cfg_save_frmt')'"'
  125.   if (RC ~= 0) then do
  126.     'IE_TO_FRONT'
  127.     'REQUEST' '"Failed to save image:' d2c(10)||dst_image'"' '" OK "'
  128.     return '<ERROR>'
  129.   end
  130.   'CLOSE' OutputImage
  131.  
  132.   back = 'OK'
  133. return back
  134.  
  135. /* Internal procedures  ---------------------------------------------- */
  136.  
  137. /*******************************************************************/
  138. /* This is where control goes when an error code is returned by IE */
  139. /* It puts up a message saying what happened and on which line     */
  140. /*******************************************************************/
  141.  
  142. error:
  143. if RC=5 then do
  144.     IE_TO_FRONT
  145.     LAST_ERROR
  146.     'REQUEST "'||RESULT||'"'
  147. end
  148. else do
  149.     IE_TO_FRONT
  150.     LAST_ERROR
  151.     'REQUEST "Error detected!!!'||D2C(10)||'Image Engineer error message is as follows'||D2C(10)||result||D2C(10)||'Script failed on line '||SIGL||'"' 'Doh!'
  152. end
  153.  
  154. return '<ERROR>'
  155.